package com.hui.xiao.xiaohui.res;

import android.animation.AnimatorInflater;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/29.
 */
public class AnimationDrawable extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_anim);
        final ImageView imageView = (ImageView) findViewById(R.id.image);
        final Animation animation = AnimationUtils.loadAnimation(this, R.anim.my_anim);
        Button bn = (Button) findViewById(R.id.bn);
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView.startAnimation(animation);
            }
        });
        LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
        ll.addView(new MyAnimationView(this));
    }

    public class MyAnimationView extends View {

        public MyAnimationView(Context context) {
            super(context);
            ObjectAnimator colorAnim = (ObjectAnimator) AnimatorInflater.loadAnimator(AnimationDrawable.this, R.animator.color_anim);
            colorAnim.setEvaluator(new ArgbEvaluator());
            colorAnim.setTarget(this);
            colorAnim.start();
        }
    }
}
